package com.daervin.svc;

import com.daervin.svc.parser.hot.TodayHubParser;
import com.daervin.svc.parser.hot.WuYiJobParSer;
import com.daervin.svc.pipeline.ResumePipeline;
import com.daervin.svc.pipeline.TodayHubPipeline;
import com.daervin.svc.service.IResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.model.HttpRequestBody;

import java.util.concurrent.ThreadPoolExecutor;

import static com.daervin.svc.common.constants.HotSiteEnum.TODAY_HUB;
import static com.daervin.svc.common.constants.HotSiteEnum.WUYI_JOB;

/**
 * @packageName: com.daervin.svc.service
 * @CLassName: ResumeEngineProcess
 * @Description:
 * @Author: wanxiong.deng
 * @Date: 2021/4/25 19:52
 */
@Component
public class ResumeEngineProcess {

    @Autowired
    private ThreadPoolTaskExecutor taskExecutor;

    @Autowired
    private IResumeService service;

    public Runnable threadWuYiJob(){
        String url = WUYI_JOB.ORG_URL;
        Request request = new Request();
        request.setUrl(WUYI_JOB.ORG_URL);
        request.addCookie("Cookie", "guid=1269d3b2abb282ab747a2def6b82a0a2; _ujz=MTc4ODA3OTM2MA%3D%3D; ps=needv%3D0; 51job=cuid%3D178807936%26%7C%26cusername%3DGAXiY4bIwhUZQHfFT09aY%252FO0iXCBDJbd5zmIk1ipGYA%253D%26%7C%26cpassword%3D%26%7C%26cname%3DFBmzJ3vhZ%252FunhuLjyfAY%252BQ%253D%253D%26%7C%26cemail%3D%26%7C%26cemailstatus%3D0%26%7C%26cnickname%3D%26%7C%26ccry%3D.0z4RR331iHXE%26%7C%26cconfirmkey%3D%25241%2524CREM5PoM%25247qOpl9vEv9ewsHR3jkoTP1%26%7C%26cautologin%3D1%26%7C%26cenglish%3D0%26%7C%26sex%3D0%26%7C%26cnamekey%3D%25241%2524s9q3FkLI%2524XGz2AqbNDgGhXa.VT4lop.%26%7C%26to%3D58ce6196ea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jTLP1TzrHf1rHRdrH6drjb0ThNkIjYkPWD4n1nYP10knjRL0ZPGujdhnycvPW9WnH0snj9-uhw90AP1UHYznH-KPbDsfW6dnj0kfRcd0A7W5HD0TA3qn0KkUgfqn0KkUgnqn0KbugwxmLK95H00XMfqn0KVmdqhThqV5HKxn7tsg1Kxn7ts0Aw9UMNBuNqsUA78pyw15HKxn7tsg1f1PHmknjPxn7ts0ZK9I7qhUA7M5H00uAPGujYs0ANYpyfqQHD0mgPsmvnqn0KdTA-8mvnqn0KkUymqn0KhmLNY5H00pgPWUjYs0ZGsUZN15H00mywhUA7M5HD0UAuW5H00uAPWujY0IZF9uARqP1msnW0z0AFbpyfqwjnYrDR3nRDYwDfsfHnsfbmvf1cdrDwjfYw7PWDvwDn0UvnqnfKBIjYs0Aq9IZTqn0KEIjYk0AqzTZfqnBnsc1nWnBnkPj6dn10LnjcWPjRsnanYPH0sQW0snj0snankc1cWnanVc108njnLrHfkc1D8nj0snj0s0Z7xIWYsQWbLg108njKxna3sn7tsQWDsg108nj-xna31n-tsQWD4g1Dzr0KBTdqsThqbpyfqn0KzUv-hUA7M5HD0mLmq0A-1gvPsmHYs0APs5H00ugPY5H00mLFW5HnYPWm%2526word%253D%2526ck%253D3306.1.100.409.541.409.539.146%2526shh%253Dwww.baidu.com%2526us%253D1.0.2.0.0.0.0%2526wd%253D%2526bc%253D110101%26%7C%26ad_logid_url%3Dhttps%253A%252F%252Ftrace.51job.com%252Ftrace.php%253Fadsnum%253D4178246%2526ajp%253DaHR0cHM6Ly9ta3QuNTFqb2IuY29tL3RnL3NlbS9MUF8yMDIwXzEuaHRtbD9mcm9tPWJhaWR1YWQ%253D%2526k%253Dd946ba049bfb67b64f408966cbda3ee9%2526bd_vid%253D10778024027003845188%26%7C%26; nsearch=jobarea%3D%26%7C%26ord_field%3D%26%7C%26recentSearch0%3D%26%7C%26recentSearch1%3D%26%7C%26recentSearch2%3D%26%7C%26recentSearch3%3D%26%7C%26recentSearch4%3D%26%7C%26collapse_expansion%3D; search=jobarea%7E%60020000%7C%21ord_field%7E%600%7C%21recentSearch0%7E%60020000%A1%FB%A1%FA000000%A1%FB%A1%FA0000%A1%FB%A1%FA00%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA9%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA0%A1%FB%A1%FA%C6%BD%C3%E6%C9%E8%BC%C6%A1%FB%A1%FA2%A1%FB%A1%FA1%7C%21recentSearch1%7E%60020000%A1%FB%A1%FA000000%A1%FB%A1%FA0000%A1%FB%A1%FA00%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA99%A1%FB%A1%FA9%A1%FB%A1%FA99%A1%FB%A1%FA%A1%FB%A1%FA0%A1%FB%A1%FA%A1%FB%A1%FA2%A1%FB%A1%FA1%7C%21; slife=lastlogindate%3D20210426%26%7C%26securetime%3DBDgBNFE2UD0AZlJsX2ZeNVNhUmc%253D");
        return Spider.create(new WuYiJobParSer(url)).addRequest(request).addUrl(url).addPipeline(new ResumePipeline(service));
    }
    public Runnable threadTodayHub(){
        String url = TODAY_HUB.ORG_URL;
        return Spider.create(new TodayHubParser(url)).addUrl(url).addPipeline(new TodayHubPipeline(service));
    }
    /**
     *
     */
    public void submit(){
        taskExecutor.submit(threadWuYiJob());
        //爬取热榜网站
        taskExecutor.submit(threadTodayHub());
    }
}
